<?php

    // define 
    define('DS', DIRECTORY_SEPARATOR);	
    define('APP_PATH', dirname(__FILE__) . DS);
    define('BASE_PATH', str_replace($_SERVER['DOCUMENT_ROOT'], '', dirname(__FILE__)) . '/');
	
    // check if the config file exists
    if(!file_exists(APP_PATH . 'config.php'))
    {
        header('location:' . BASE_PATH . 'install');
    }
	
	// get the required files
    require_once(APP_PATH . 'config.php');
    require_once(APP_PATH . 'inc' . DS . 'cookie.class.php');
	require_once(APP_PATH . 'inc' . DS . 'db.class.php');
	require_once(APP_PATH . 'inc' . DS . 'user_agent.class.php');
    
    // adds slashes and trims the string
    function add($str) 
    {
        if(is_array($str) || is_object($str)) 
        {
            foreach($str as $key => $value) 
            {
                if(is_array($str)) 
                {
                    $str[$key] = add($value);
                } 
                else 
                {
                    $str->$key = add($value);
                }
            }
        } 
        else 
        {
            $str = trim(get_magic_quotes_gpc() ? $str : addslashes($str));
        }
        return $str;
    }

    // removes the slashes from the string
    function strip($str) 
    {
        if(is_array($str) || is_object($str)) 
        {
            foreach($str as $key => $value) 
            {
                if(is_array($str)) 
                {
                    $str[$key] = strip($value);
                } 
                else 
                {
                    $str->$key = strip($value);
                }
            }
        } 
        else 
        {
            $str = get_magic_quotes_gpc() ? $str : stripslashes($str);
        }
        return $str;
    }


	// make sure the $_POST and $_GET are safe
	$_GET = add($_GET);
	$_POST = add($_POST);

	// make an instance
	$cookie = new Cookie();
	$db = new DB();
	$user_agent = new UserAgent();

?>